home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / 140_01.zip / VERIFY.C < prev    next >
Text File  |  1993-06-26  |  9KB  |  508 lines

  1. /*******************************************************\
  2. *                            *
  3. *    VERIFY: by Steve de Plater            *
  4. *                            *
  5. *    66 Priam St.                    *
  6. *    Chester Hill NSW, 2224, Australia        *
  7. *    Phone (02) 644 4009                *
  8. *                            *
  9. \*******************************************************/
  10.  
  11.  
  12. #include    bdscio.h
  13.  
  14. #define        VERSION    "1.1"
  15. #define        STACKSPACE    0x1000
  16. #define        DATE    "28 Sep 81"
  17. #define        TIME    "17:37"
  18.  
  19.  
  20. char    mask    [50];        /* File match mask    */
  21. char    work_mask [16];
  22. int    masks;
  23. int    matched;
  24. char    mask2    [36];        /* to expand masks into */
  25. int    not_mask;        /* flag for '!'     */
  26. char    fcb1    [36];        /* used for bdos calls    */
  27. char    fn    [14];
  28. char    fnp    [12];        /* fn for display    */
  29. int    code;
  30. int    files;
  31. int    copies;
  32. char    *dir;            /* Where the DIR goes    */
  33. char    *dbuf1;            /* First Buffer pointer */
  34. char    *dbuf2;            /* 2nd   Buffer pointer    */
  35. unsigned stackspace;
  36. int    sectors;        /* buffer size        */
  37. char    id;            /* assorted disk drive    */
  38. char    od;            /* specifiers..        */
  39. char    ld;
  40. char    fn1    [16];
  41. char    fn2    [16];
  42. char    temp    [20];
  43. int    errors;
  44. int    ctr_z;
  45. int    no_wait;
  46. int    debug;
  47. int    dummy;        /* not used - just to stay the    */
  48.             /* same as backup.c (getclp())    */
  49. char    found_eof;
  50. int    total_found;
  51. int    total_copied;
  52. int    no_questions;
  53.  
  54.  
  55. main (argc,argv)
  56. char    **argv;
  57.  
  58. {
  59.     int    x;
  60.     int    p,z;
  61.     char    *y;
  62.  
  63.     y = 0x501;    *y = 0x20;
  64.  
  65.     stackspace = STACKSPACE;
  66.     dir = endext ();
  67.  
  68.     printf ("\nVERIFY, ver %s, ",VERSION);
  69.     printf ("1981, by Steve de Plater\n\n");
  70.  
  71.     if (argc < 2)
  72.       getmask ();
  73.     else
  74.       strcpy (mask,argv[1]);
  75.     ld=bdos(25) + 'A';
  76.  
  77.     getclp (argc,argv,
  78.         &id,&od,&dummy,&ctr_z,&no_wait,&debug);
  79.     total_found = total_copied = matched = copies = 0;
  80.     no_questions = TRUE;
  81.     do_it ();
  82. }
  83.  
  84. getmask ()
  85.  
  86. {
  87.     int    x;
  88.  
  89.     printf ("Which files?  ");
  90.     gets (mask);
  91.     for (x=0; *(mask+x); x++)
  92.       *(mask+x) = toupper (*(mask+x));
  93.     no_questions = FALSE;
  94. }
  95.  
  96. getdir (fcb)
  97. char    *fcb;
  98.  
  99. {
  100.     int    x,y,z;
  101.     char    *s;
  102.  
  103.     y=files<<4;
  104.     s=0x80+(code<<5);
  105.     if (*(s+12)) return;
  106.     files++;
  107.     for (x=0; x<16; x++)
  108.     {
  109.       dir[y]=*(s+x);
  110.       y++;
  111.     }
  112. }
  113.  
  114. match_mask (s)
  115. char    *s;
  116.  
  117. {
  118.     int    x,y;
  119.  
  120.     y=TRUE;
  121.     for (x=1; x<12; x++)
  122.       if (((*(s+x)&0x7f) != mask2[x]) &&
  123.           (mask2[x]         != '?'    ))
  124.         y=FALSE;
  125.     if (not_mask)
  126.       return !y;
  127.     else
  128.       return y;
  129. }
  130.  
  131. does_exist (s)
  132. char    *s;
  133.  
  134. {
  135.     char    fcb [36];
  136.  
  137.     setfcb (fcb,s);
  138.     if (bdos (17,fcb) > 3)
  139.       return FALSE;
  140.     else
  141.       return TRUE;
  142. }
  143.  
  144. check (s1,s2)
  145. char    *s1,*s2;
  146.  
  147. {
  148.     int    fd1,fd2;
  149.     int    x,y,z,size_err;
  150.     int    records;
  151.  
  152.     errors =0;
  153.     records=0;
  154.     found_eof = size_err = FALSE;
  155.  
  156.     if ((fd1=open (s1,0)) == ERROR)
  157.     {
  158.       printf (" FATAL ERROR: Can't find '%s'\n",s1);
  159.       quit (1);
  160.     }
  161.     if ((fd2=open (s2,0)) == ERROR)
  162.     {
  163.       printf (" FATAL ERROR: Can't find '%s'\n",s2);
  164.       quit (1);
  165.     }
  166.  
  167.     while (TRUE)
  168.     {
  169.       x = read (fd1,dbuf1,sectors);
  170.       if (!x)
  171.         break;
  172.       y = read (fd2,dbuf2,sectors);
  173.       if (!y)
  174.         break;
  175.       if (y != x)
  176.         size_err = TRUE;
  177.       records += compare (dbuf1,dbuf2,x);
  178.       if (x < sectors) break;
  179.       if (found_eof) break;
  180.     }
  181.     fabort (fd1);
  182.     fabort (fd2);
  183.     if (!errors)
  184.     {
  185.       printf ("%5d records checked (OK)\n",records);
  186.       copies++;
  187.     }
  188.     else
  189.       if ((size_err) && (!found_eof))
  190.         printf ("      SIZE ERROR\n");
  191.       else
  192.         printf ("%5d ERRORS FOUND (BYTES)\n",errors);
  193. }
  194.  
  195. quit (a)
  196. int    a;
  197.  
  198. {
  199.     if (!a)
  200.     {
  201.       printf ("%d file",matched);
  202.       if (matched != 1)
  203.         putch ('s');
  204.       printf (" checked, %d verified\n",copies);
  205.     }
  206.     total_found += matched;    matched = 0;
  207.     total_copied += copies;    copies = 0;
  208.  
  209.     if (!no_wait)
  210.     {
  211.       printf ("\nMore ? ");
  212.       if (toupper (getchar ()) == 'Y')
  213.       {
  214.         printf ("\n\n");
  215.         getmask ();
  216.         id = od = FALSE;
  217.         do_it ();
  218.       }
  219.       printf ("\n\nTotal Matched %d, Total verified %d",
  220.             total_found,total_copied);
  221.       printf ("\nMount system disk on drive '%c'\n",ld);
  222.       printf ("  press <CR> to continue: ");
  223.       bios (3);    putch ('\n');
  224.     }
  225.     exit (0);
  226. }
  227.  
  228. trim_mask (s)
  229. char    *s;
  230.  
  231. {
  232.     char    *x;
  233.     char    t[16];
  234.  
  235.     x=s;
  236.     if (*(x+1) == ':')
  237.       x+=2;
  238.     strcpy (t,x);
  239.     strcpy (s,t);
  240. }
  241.  
  242. compare (s1,s2,a)
  243. char    *s1;
  244. char    *s2;
  245. int    a;
  246.  
  247. {
  248.     int    x,y;
  249.  
  250.     y=a<<7;            /* y = a * 128    */
  251.     if (ctr_z)
  252.       for (x=0; x<y; x++)
  253.       {
  254.         if ((*(s1+x) == CPMEOF) ||
  255.             (*(s2+x) == CPMEOF))
  256.         {
  257.           found_eof = TRUE;
  258.           return ((x>>7)+1);
  259.         }
  260.         if (*(s1+x) != *(s2+x))
  261.           errors++;
  262.       }
  263.     else
  264.       for (x=0; x<y; x++)
  265.         if (*(s1+x) != *(s2+x))
  266.           errors++;
  267.     return a;
  268. }
  269.  
  270. getclp (argc,argv,i,o,v,z,n,d)
  271. int    argc;
  272. char    **argv;
  273. char    *i;        /* source disk            */
  274. char    *o;        /* destination disk        */
  275. int    *v;        /* verify flag            */
  276. int    *z;        /* CP/M EOF (^Z) flag        */
  277. int    *n;        /* no stop for disk change flag */
  278. int    *d;        /* debug flag            */
  279.  
  280. {
  281.     char    line [50];
  282.     int    x;
  283.  
  284.     *i=*o=*v=*z=*n=*d=FALSE;
  285.     if (argc<3) return;
  286.     strcpy (line,argv[2]);
  287.     for (x=3; x<argc; x++)
  288.       strcat (line,argv[x]);
  289.     for (x=0; x<strlen(line); x++)
  290.       switch (line[x])
  291.       {
  292.         case '<': { *i=line[x+1]; x++;  break; }
  293.         case '>': { *o=line[x+1]; x++;  break; }
  294.         case '(': { *i=line[x+1]; x++;  break; }
  295.         case ')': { *o=line[x+1]; x++;  break; }
  296.         case 'V': { *v=TRUE;        break; }
  297.         case 'Z': { *z=TRUE;        break; }
  298.         case 'N': { *n=TRUE;        break; }
  299.         case 'D': { *d=TRUE;        break; }
  300.       }
  301. }
  302.  
  303. block_check (s)
  304. char    *s;
  305.  
  306. {
  307.     int    x,z,p;
  308.     char    *y;
  309.     int    block_size;
  310.  
  311.     printf ("Matching mask '%s'\n\n",s);
  312.  
  313.     block_size=0;
  314.     for (x=0; x<files; x++)
  315.     {
  316.       y=dir+(x<<4);
  317.       if (!match_mask (y))
  318.         continue;
  319.       if (*y == 0xe5)
  320.         continue;
  321.       block_size++;
  322.       *y = 0xe5;
  323.  
  324.       for (z=0; z<20; z++)    temp[z]=NULL;
  325.  
  326.       for (z=1,p=0; z<9; z++,p++)
  327.         temp[p] = *(y+z);
  328.       while (temp[strlen(temp)-1]==0x20)
  329.         temp[strlen(temp)-1]=NULL;
  330.  
  331.       strcat (temp,".");    p=strlen (temp);
  332.  
  333.       for (z=9; z<12; z++,p++)
  334.         temp[p] = *(y+z)&0x7f;
  335.  
  336.       fn1[0]=id;    fn2[0]=od;
  337.       fn1[1]=':';    fn2[1]=':';
  338.       fn1[2]=0;    fn2[2]=0;
  339.       strcpy (fnp,temp);
  340.       for (z=0; z<12; z++)
  341.         fnp[z]=fnp[z]&0x7f;
  342.       strcat (fn1,temp);
  343.       strcat (fn2,temp);
  344.       if (does_exist (fn2))
  345.       {
  346.         printf ("Verifying %-12.12s - ",fnp);
  347.         check (fn1,fn2);
  348.         matched++;
  349.       }
  350.     }
  351.     if (!block_size)
  352.       printf ("NO FILE\n");
  353.     printf ("\n");
  354. }
  355.  
  356. mask_num (a)
  357. int    a;
  358.  
  359. {
  360.     int    x,y,z;
  361.  
  362.     y=z=0;
  363.     for (x=0; x<16; x++)
  364.       work_mask[x] = NULL;
  365.     for (x=0; x<strlen(mask); x++)
  366.     {
  367.       if (mask[x] == ',')
  368.         y++;
  369.       if (y==a)
  370.         break;
  371.     }
  372.     if (x >= strlen (mask))
  373.       return;
  374.     if (x)
  375.       x++;
  376.     for (y=x; y<strlen(mask); y++,z++)
  377.     {
  378.       if (mask[y] == ',')
  379.         break;
  380.       work_mask[z] = mask[y];
  381.     }
  382.     trim_mask (work_mask);
  383.     if (work_mask[0]=='!')
  384.     {
  385.       for (x=0; x<13; x++)
  386.         work_mask[x]=work_mask[x+1];
  387.       not_mask=TRUE;
  388.     }
  389.     else
  390.       not_mask=FALSE;
  391.     setfcb (mask2,work_mask);
  392. }
  393.  
  394. do_it ()
  395.  
  396. {
  397.     int    x,p,z;
  398.     char    *y;
  399.  
  400.  
  401.     if (!id)
  402.     {
  403.       printf ("First Drive:  ");
  404.         id = toupper (bios (3));
  405.       if (id != '\r')
  406.         putch (id);
  407.       putch ('\n');
  408.       no_questions = FALSE;
  409.     }
  410.     if (!od)
  411.     {
  412.       printf ("Second Drive: ");
  413.         od = toupper (bios (3));
  414.       if (od != '\r')
  415.         putch (od);
  416.       putch ('\n');
  417.       no_questions = FALSE;
  418.     }
  419.  
  420.     if (id == '\r') id=ld;
  421.     if (od == '\r') od=ld;
  422.     if (id == od)
  423.     {
  424.       printf ("FIRST & SECOND DRIVES MUST DIFFER!\n");
  425.       exit (1);
  426.     }
  427.     if ((id < 'A') || (id > 'P') ||
  428.         (od < 'A') || (od > 'P'))
  429.     {
  430.       printf ("INVALID DRIVE NAME!\n");
  431.       exit (1);
  432.     }
  433.  
  434.     if (!no_questions)
  435.       printf ("\n");
  436.  
  437.     if (!no_wait)
  438.     {
  439.       printf ("Mount disks, <CR> to continue: ");
  440.       bios (3);
  441.       printf ("\n\n");
  442.       bdos (13);
  443.     }
  444.  
  445.     files = 0;
  446.     temp[0]=id;    temp[1]=':';    temp[2]=0;
  447.     strcat (temp,"*.*");
  448.     setfcb (fcb1,temp);
  449.  
  450.     code = bdos (17,fcb1);    /* search for first    */
  451.     if (code > 3)
  452.     {
  453.       printf ("NO FILE\n");
  454.       quit (1);
  455.     }
  456.     getdir (fcb1);
  457.     while (TRUE)
  458.     {
  459.       code = bdos (18);
  460.       if (code > 3)
  461.         break;
  462.       getdir (fcb1);
  463.     }
  464.  
  465.     config2();
  466.     masks=0;
  467.     mask_num (0);
  468.     while (strlen(work_mask))
  469.     {
  470.       block_check (work_mask);
  471.       masks++;
  472.       mask_num (masks);
  473.     }
  474.     quit (0);
  475. }
  476.  
  477. config2 ()
  478.  
  479. {
  480.     unsigned    x,p,z;
  481.     char        *y,*top,*mid;
  482.  
  483.     x = 16*files;
  484.     p = (dir + x +0x101);
  485.     dbuf1 = z = p & 0xff00;
  486.     p = (topofmem() - stackspace) & 0xff00;
  487.     sectors = (p - z) >> 8;
  488.     dbuf2 = dbuf1 + (sectors << 7);
  489.     sectors--;            /* for safety!!    */
  490.  
  491.     if (sectors < 8)
  492.     {
  493.       printf ("NOT ENOUGH RAM FOR THIS PROGRAMME!\n");
  494.       quit (1);
  495.     }
  496.     if (debug)
  497.     {
  498.       printf ("Compiled on %s, at %s\n\n",DATE,TIME);
  499.  
  500.       printf ("Directory assigned at: %04x\n",dir);
  501.       printf ("Entries found:         %4d\n", files);
  502.       printf ("Buffer 1 assigned at:  %04x\n",dbuf1);
  503.       printf ("Buffer 2 assigned at:  %04x\n",dbuf2);
  504.       printf ("Max. Records Buffered: %4d\n", sectors);
  505.       printf ("Stackspace reserved:   %04x\n",stackspace);
  506.       printf ("Top of Buffers at:     %04x\n\n",p);
  507.     }
  508. }